package com.sxz.sbs.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.blankj.utilcode.util.Utils;

/**
 * 偏好设置文件
 * @author tian
 */
public class PreferencesUtil {

	SharedPreferences sp;
	SharedPreferences.Editor editor;

	public PreferencesUtil(String name) {
		sp = Utils.getApp().getSharedPreferences(name, Context.MODE_PRIVATE);
		editor = sp.edit();
	}

	public void setValue(String key, String value) {
		editor.putString(key, value);
		editor.commit();
	}

	public String getValue(String key, String defaultValue) {
		return sp.getString(key, defaultValue);
	}

	public String getValue(String key) {
		return sp.getString(key, null);
	}

	public void setBooleanValue(String key, boolean value) {
		editor = sp.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public boolean getBooleanValue(String key, boolean defaultValue) {
		return sp.getBoolean(key, defaultValue);
	}


	public void setLongValue(String key, long time) {
		editor = sp.edit();
		editor.putLong(key, time);
		editor.commit();
	}
	public void setFloatValue(String key, float time) {
		editor = sp.edit();
		editor.putFloat(key, time);
		editor.commit();
	}
	public long getLongValue(String key, long defaultValue) {
		return sp.getLong(key, defaultValue);
	}


	public void remove(String name) {
		editor.remove(name);
	}

	public void clear() {
		editor.clear();
		editor.commit();
	}
	public SharedPreferences getSpReader() {
		return sp;
	}

	public  SharedPreferences.Editor getSpWriter() {
		return editor;
	}
}
